//
//  BIDAnnouncementDetailViewController.m
//  JuanChengOA
//
//  Created by mal on 2017/7/26.
//  Copyright © 2017年 mal. All rights reserved.
//

static NSString *detailURL = @"townAndroid!detailAnnounce.action";

#import "BIDAnnouncementDetailViewController.h"

@interface BIDAnnouncementDetailViewController ()

@end

@implementation BIDAnnouncementDetailViewController
@synthesize announcementID;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"详情";
    [_webView setBackgroundColor:[UIColor clearColor]];
    [_webView setOpaque:NO];
    [self loadData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)loadData
{
    NSString *strRequestURL = [[NSString alloc] initWithFormat:@"%@/%@", [AppDelegate getServerAddr], detailURL];
    NSString *strPost = [[NSString alloc] initWithFormat:@"id=%@", announcementID];
    [self sendHttpRequestWithURL:strRequestURL postData:strPost withCompletion:^(NSDictionary *responseDic, NSString *errMsg){
        if(errMsg)
        {
            [self showAlertView:errMsg buttonTitle:ALERT_BTN_TITLE tag:0 functionName:nil];
        }
        else
        {
            NSMutableString *strResultContent = [NSMutableString string];
            NSString *strTitle = responseDic[@"townWork"][@"title"];
            NSString *strDate = responseDic[@"townWork"][@"announceTime"];
            NSString *strContent = responseDic[@"townWork"][@"content"];
            if(strTitle.length > 0)
            {
                [strResultContent appendFormat:@"<p style='margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: normal; color: rgb(0, 0, 0); font-size: 22px; line-height: 32px; font-family: 微软雅黑; font-weight:900, widows: 1;'>%@</p>", strTitle];
            }
            if(strDate.length > 0)
            {
                [strResultContent appendFormat:@"<p style='margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: normal; color: rgb(0, 0, 0); font-size: 11px; line-height: 32px; font-family: 微软雅黑; widows: 1;'>%@</p>", strDate];
            }
            NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[strContent dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
            [strResultContent appendString:strContent];
            [_webView loadHTMLString:strResultContent baseURL:nil];
        }
    }];
}

@end
